package com.qsl.ssyx.home.api;


import com.qsl.ssyx.common.Interceptor.AuthContextHolder;
import com.qsl.ssyx.common.result.Result;
import com.qsl.ssyx.home.service.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(tags = "微信小程序-商品详情")
@RestController
@RequestMapping("/api/home")
public class ItemApiController {

    @Autowired
    private ItemService itemService;

    @ApiOperation("根据商品Id及用户id获取商品详情")
    @GetMapping("item/{id}")
    public Result SkuInfoBySkuIdAndUserId(@ApiParam(value = "商品Id", required = true)
                                          @PathVariable("id") Long skuId) {
        Long userId = AuthContextHolder.getUserId();
        Map<String, Object> map = itemService.SkuInfoBySkuIdAndUserId(skuId, userId);
        return Result.ok(map);
    }

}
